package com.example.designpatternproject.observer;


/**
 * @ClassName: ObservableManager
 * @Author: 史大拿
 * @CreateDate: 10/26/22$ 2:34 PM$
 * TODO
 */
public class ObservableManager {

    private ObservableManager() {
        observables = new ObservableImpl();
    }

    private static volatile ObservableManager instance;

    private final Observable<String, ObserverActivity> observables;

    public static ObservableManager getInstance() {
        if (instance == null) {
            synchronized (ObservableManager.class) {
                if (instance == null)
                    instance = new ObservableManager();
            }
        }
        return instance;
    }

    public void register(ObserverActivity activity) {
        observables.addObserver(activity);
    }

    public void unregister(ObserverActivity activity) {
        observables.removeObserver(activity);
    }

    public void onChanged(String value) {
        observables.onChanged(value);
    }
}
